﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using PoemGame.Domain.GameAggregate;

namespace PoemGame.Domain.Services.Factory.WebApi
{
    public class CheckGameConditionServiceFactory : IDomainServiceFactory<ICheckGameConditionService>
    {
        private readonly IConfiguration _configuration;
        private readonly IHttpClientFactory httpClientFactory;
        public CheckGameConditionServiceFactory(IConfiguration configuration, IHttpClientFactory httpClientFactory)
        {
            _configuration = configuration;
            this.httpClientFactory = httpClientFactory;
        }

        public ICheckGameConditionService GetService(GameType gamePlayType)
        {
            var remoteurl = _configuration["CheckConditionServices:"
                                          + gamePlayType.MainType + "_" + gamePlayType.SubType];
            var httpClient=this.httpClientFactory.CreateClient();
        
            httpClient.Timeout = new TimeSpan(0, 0, 30);
            return new CheckGameConditionServiceRemote(httpClient, remoteurl);
        }
    }
}
